package cau.se.project.unittest;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import cau.se.project.data.DSMRow;
import cau.se.project.data.method.GroupControl;
import cau.se.project.data.method.RowControl;

import static org.hamcrest.CoreMatchers.is;

import static org.easymock.EasyMock.*;

public class DSMRowTest {
	private RowControl dsmRow;
	private RowControl otherRow;
	private GroupControl groupControl;
	
	@Before
	public void setUp() throws Exception {
		dsmRow = new DSMRow("DSMRowTest");
		otherRow = new DSMRow("OtherRow");
		groupControl = createMock(GroupControl.class);
	}

	@Test
	public void testRemoveDependency() {
		dsmRow.setDependency(otherRow);
		
		dsmRow.removeDependency(otherRow);
		
		assertTrue(dsmRow.getDepenencyList().isEmpty());
	}

	@Test
	public void testSetDependency() {
		assertTrue(dsmRow.getDepenencyList().isEmpty());
		
		dsmRow.setDependency(otherRow);
		
		assertThat(dsmRow.getDepenencyList().get(0), is(otherRow));
	}

	@Test
	public void testSetName() {
		assertThat(dsmRow.getName(), is("DSMRowTest"));
		
		dsmRow.setName("New Name");

		assertThat(dsmRow.getName(), is("New Name"));
	}
	
	@Test(expected=Exception.class)
	public void testSetNameWithException() {
		dsmRow.setName(null);
	}

	@Test
	public void testGetName() {
		assertThat(dsmRow.getName(), is("DSMRowTest"));
	}

	@Test
	public void testGetChildAt() {
		assertNull(dsmRow.getChildAt(0));
	}

	@Test
	public void testGetChildCount() {
		assertThat(dsmRow.getChildCount(), is(0));
	}

	@Test
	public void testGetParentAndSetParent() {
		assertNull(dsmRow.getParent());
		
		dsmRow.setParent(groupControl);
		
		assertThat((GroupControl)dsmRow.getParent(), is(groupControl));
	}

	@Test
	public void testGetIndex() {
		assertThat(dsmRow.getIndex(otherRow), is(-1));
		assertThat(dsmRow.getIndex(null), is(-1));
	}

	@Test
	public void testGetAllowsChildren() {
		assertFalse(dsmRow.getAllowsChildren());
	}

	@Test
	public void testIsLeaf() {
		assertTrue(dsmRow.isLeaf());
	}

	@Test
	public void testChildren() {
		assertNull(dsmRow.children());
	}

	@Test
	public void testGetDepenencyList() {
		assertThat(dsmRow.getDepenencyList().size(), is(0));
		
		dsmRow.setDependency(otherRow);
		
		assertThat(dsmRow.getDepenencyList().get(0), is(otherRow));
	}

	@Test
	public void testGetDepth() {
		assertThat(dsmRow.getDepth(), is(0));
	}

}
